package com.study.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 配置登录请求转发规则
 */
@Configuration
public class RouteLoacatorConfig {

    /**
     * 使用代码定义路由规则 在网关层面拦截下登录和注册接口
     *
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator loginRouteLocator(RouteLocatorBuilder builder) {

        //手动定义 gateway 路由规则需要指定 id、path、uri
        return builder.routes()
                .route(
                        "ecommerce_authority",
                        r -> r.path(
                                "/study/ecommerce/login",
                                "/study/ecommerce/register"
                        ).uri("http://lcoalhost:9001/")
                ).build();
    }
}
